// firstPackage/pages/msgModule/sysMsgList/sysMsgList.js


import {
  queryMyCustomList
} from "../../../service/jb_common_service"

let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    themeStyle: "",
    sysList: [

    ],
    page: 1,
    pageSize: 20,
    scrollRefreshStatus: true,
    isShowLoading: false,
    isBottomShow: false,
    refreshFlag: false,
    customList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {


  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (app.globalData.themeStyle) {
      this.setData({
        themeStyle: app.globalData.themeStyle
      })
    }
    this.queryMyCustomList();
  },
  createCustomAction() {
    wx.navigateTo({
      url: '/featurePackage/pages/privateCustomSubmit/privateCustomSubmit',
    })
  },
  //查询是否已有定制列表
  queryMyCustomList() {
    wx.showLoading();
    queryMyCustomList().then(res => {
      wx.hideLoading();
      if (res.code == 200) {

        this.setData({
          customList: res.data.list || [],
          isBottomShow: true,
          refreshFlag: false,
        })
        setTimeout(() => {
          let arr = this.data.customList || []
          if (arr.length > 0) {
            arr.forEach((i, index) => {

              if (index == 0) {
                i.isUnfold = true;
              } else {
                i.isUnfold = false;
              }
            })
            this.setData({
              customList: arr,
            })
          }
        }, 1000);
      }
    }).catch(err => {
      wx.hideLoading();
      this.setData({
        customList: [],
      })
    })
  },



  //跳转到定制回复详情去
  pushToBackDetail(e) {
    let item = e.currentTarget.dataset.item;
    let index = e.currentTarget.dataset.index;
    item.isUnfold = !item.isUnfold;
    let cItem = 'customList[' + index + ']';
    this.setData({
      [cItem]: item,
    })
    // app.globalData.customDetailData = item;
    // wx.navigateTo({
    //   url: '/featurePackage/pages/privateCallDetail/privateCallDetail',
    // })
  },


  // 下拉刷新
  handleRefresh() {
    // TODO
    this.setData({
      page: 1,
      isBottomShow: false,
      refreshFlag: true,
    })
    this.queryMyCustomList();
  },









})